/**
  ******************************************************************************
  * @file    usbd_cdc.h
  * @author  MCD Application Team
  * @brief   header file for the usbd_cdc.c file.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2015 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under Ultimate Liberty license
  * SLA0044, the "License"; You may not use this file except in compliance with
  * the License. You may obtain a copy of the License at:
  *                      http://www.st.com/SLA0044
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USB_CDC_H
#define __USB_CDC_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include  "usbd_ioreq.h"
#include "main.h"
#include "../DDIC/AllDDIC.h"
#include "iic_current.h"
#include "stm32f7xx.h"                  // Device header
#define InsertBlack     0
#define SSD_Command_16
#define DSI_Set_Window_EN   0       //0:Disable  1:Enable
#define SPI_Set_Window_EN   0       //0:Disable  1:Enable

#define BMP_R_Byte_Max  8192*2//2560*3*2
#define SSD2832_Code_Max				32
#define SSD2832_SCM_Code_Max		32


#define IniCode_Max		          255
#define IniCode_table_num				50

typedef struct {
	u16 H_pixel;
	u8	H_Back;
	u8	H_Front;
	u8	H_Sync;
	u16 V_pixel;
	u8	V_Back;
	u8	V_Front;
	u8	V_Sync;
	u8 DisMode;	//0:????,1:??????,2:??????
	u8 SigMode;	//0x:MCU      1x:MIPI    2x:SPI3     3x:SPI4
	u8 RGBMode;
	u8 PHYMode; //0:D-PHY   1:C-PHY  
	float pixel_clk;

} OLED_Para;

extern u32 WriteAddress; //Base address of Sector 2
extern u8  buffer[BMP_R_Byte_Max];
extern u32 buffer1[BMP_R_Byte_Max-1];
extern u32 i,k;
extern u32 j;
extern u8 Valid_BMP_No;
extern u8	Uart_rx_flag;
extern u32 File_length;
extern OLED_Para OLED;
extern __IO  uint32_t  USB_ReceivedCount;
extern uint8_t USB_Rx_Buffer[];   //[CDC_DATA_HS_IN_PACKET_SIZE];
extern u8 NUM;
extern u8 SendTo_PC_cfgFile;
extern __IO  uint8_t USB_StatusDataSended;
extern u32 ICS307_Buf_Data;
extern u32 ICS307_Buf_Data1;
extern u32 ICS307_Valid_Data;
extern u8 PatternR,PatternG,PatternB;
extern u8 Pure_Color_Flag;
extern u8  Rec_first_line_Flag;
extern u32 SSD28xx_Code[SSD2832_Code_Max];                         //?? SSD2832?? ??
extern u32 SSD28xx_SCM_Data[SSD2832_SCM_Code_Max];                 //??SSD2832 SCM REG Data
extern u16 SSD28xx_SCM_Cmd[SSD2832_SCM_Code_Max];		
extern u32 Timing_and_InitCode[IniCode_Max];                       //??? ????Timing?Driver IC?????
extern u8  SSD28xxCode_count;                                  //SSD2832????? ??
extern u8  SSD28xx_SCM_Code_count;
extern u8  InitCode_valid[IniCode_table_num][IniCode_Max];         //?? Driver IC?????
extern u8  Buffer_ReadCode[255];
extern u32 InitCode_count;                                     //DriverIC?????? ??
extern u32 Code_length;
extern u32 bw;
extern u8  Receive_BIN_Flag;
extern u8  Receive_BIN_Flag1;
extern u32 VCP_Receive_True_num;
extern  u32 USB_Rx_Demura;
extern u32 Receive_BIN_Length;
extern u16 LP_B7_Data;
extern u16 HS_B7_Data;

extern u32  Device_ID_Buf[2];
extern u32  Device_ID;
extern u32  Device_Addr;	 
	 
/** @addtogroup STM32_USB_DEVICE_LIBRARY
  * @{
  */

/** @defgroup usbd_cdc
  * @brief This file is the Header file for usbd_cdc.c
  * @{
  */
#define Uart_Error_None						0x00
#define Uart_Error_Oth						0x02
#define Uart_Error_IntFlash					0x03        //flash???? ???? ??

#define REC_LCDCONF_START					0x0A
#define REC_LCDCONF_NUM						0x19  //25
#define REC_W_LCDCONF_FLAG					0x01
#define REC_W_DISP_WINDOW_CONF_FLAG	0x11
#define REC_LCDCONF_CONVERT					0x12  //特殊情况下在线切换OLED MIPI/SPI Config,详情咨询chenfeng
#define OLEDConfigPowerSetting				0x13
#define REC_R_LCDCONF_FLAG					0x02
#define REC_W_PATTERN_FLAG					0x07		//Write Pattern
#define REC_W_RARTIAL_PATTERN_FLAG			0x17		//logic Pattern
#define REC_W_EDIT_LOGIC_PATTERN_FLAG		0x18		//logic Pattern
#define REC_R_PATTERN_FLAG					0x08		//Read Pattern
#define PrevPic								0x01b 
#define NextPic				    			0x01c 
// 0xFA 0xFB 0xFC  --for demuraIP
// 0xF9 --SSD2832 bist mode test
#define REC_W_DeviceID_FLAG      			0x0E
#define REC_UPDATABIN_Start					0x55
#define DemuraIPConfig						0x66  //包长为12时用于区分CFG/BMP,其他长度用于Demura IP相关参数设定

#define REC_R_SW_VERSION_FLAG				0x0D
#define REC_SSD_CODE_START					0x0D
#define REC_SSD_READ_START					0x1D   ////SSD2828/2832 寄存器回读

#define Rec_R_Config_Start					0x0B   //上位机  读取  配置文件 命令
#define Rec_R_Config_flag					0x01

//#define BMP_FLAG							0xBD   //---重要,但千万勿删！
#define REC_W_SSD_FLAG						0x01
#define REC_W_SSD_ONE_FLAG					0x03
#define REC_W_SSD_SCM_FLAG					0x05
#define REC_W_SSD_SCM_ONE_FLAG				0x06
#define REC_W_CODE_FLAG				   	 	0x02
#define REC_W_CODE_ONE_FLAG					0x04
#define REC_R_CODE_FLAG						0x07


//#define EE_GMA			  0x90
//#define HFGenWR			  0x96    //0x96 for HefeiGEN W/R reg
//#define GenWR               0x99
//#define GenWRHFZ            0x9F
//#define GenSTM32FSMC2FPGA   0x9D
//#define PMU_MTR             0x9E
//#define IICWrite_Read       0x9A

/** @defgroup usbd_cdc_Exported_Defines
  * @{
  */
#define CDC_IN_EP                                   0x81U  /* EP1 for data IN */
#define CDC_OUT_EP                                  0x01U  /* EP1 for data OUT */
#define CDC_CMD_EP                                  0x82U  /* EP2 for CDC commands */

#ifndef CDC_HS_BINTERVAL
  #define CDC_HS_BINTERVAL                          0x10U
#endif /* CDC_HS_BINTERVAL */

#ifndef CDC_FS_BINTERVAL
  #define CDC_FS_BINTERVAL                          0x10U
#endif /* CDC_FS_BINTERVAL */

/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
#define CDC_DATA_HS_MAX_PACKET_SIZE                 512U  /* Endpoint IN & OUT Packet size */
#define CDC_DATA_FS_MAX_PACKET_SIZE                 64U  /* Endpoint IN & OUT Packet size */
#define CDC_CMD_PACKET_SIZE                         8U  /* Control Endpoint Packet size */

#define USB_CDC_CONFIG_DESC_SIZ                     67U
#define CDC_DATA_HS_IN_PACKET_SIZE                  CDC_DATA_HS_MAX_PACKET_SIZE
#define CDC_DATA_HS_OUT_PACKET_SIZE                 CDC_DATA_HS_MAX_PACKET_SIZE

#define CDC_DATA_FS_IN_PACKET_SIZE                  CDC_DATA_FS_MAX_PACKET_SIZE
#define CDC_DATA_FS_OUT_PACKET_SIZE                 CDC_DATA_FS_MAX_PACKET_SIZE

/*---------------------------------------------------------------------*/
/*  CDC definitions                                                    */
/*---------------------------------------------------------------------*/
#define CDC_SEND_ENCAPSULATED_COMMAND               0x00U
#define CDC_GET_ENCAPSULATED_RESPONSE               0x01U
#define CDC_SET_COMM_FEATURE                        0x02U
#define CDC_GET_COMM_FEATURE                        0x03U
#define CDC_CLEAR_COMM_FEATURE                      0x04U
#define CDC_SET_LINE_CODING                         0x20U
#define CDC_GET_LINE_CODING                         0x21U
#define CDC_SET_CONTROL_LINE_STATE                  0x22U
#define CDC_SEND_BREAK                              0x23U

/**
  * @}
  */


/** @defgroup USBD_CORE_Exported_TypesDefinitions
  * @{
  */

/**
  * @}
  */
typedef struct
{
  uint32_t bitrate;
  uint8_t  format;
  uint8_t  paritytype;
  uint8_t  datatype;
}USBD_CDC_LineCodingTypeDef;

typedef struct _USBD_CDC_Itf
{
  int8_t (* Init)          (void);
  int8_t (* DeInit)        (void);
  int8_t (* Control)       (uint8_t cmd, uint8_t* pbuf, uint16_t length);
  int8_t (* Receive)       (uint8_t* Buf, uint32_t *Len);

}USBD_CDC_ItfTypeDef;


typedef struct
{
  uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE / 4U];      /* Force 32bits alignment */
  uint8_t  CmdOpCode;
  uint8_t  CmdLength;
  uint8_t  *RxBuffer;
  uint8_t  *TxBuffer;
  uint32_t RxLength;
  uint32_t TxLength;

  __IO uint32_t TxState;
  __IO uint32_t RxState;
}
USBD_CDC_HandleTypeDef;



/** @defgroup USBD_CORE_Exported_Macros
  * @{
  */

/**
  * @}
  */

/** @defgroup USBD_CORE_Exported_Variables
  * @{
  */

extern USBD_ClassTypeDef  USBD_CDC;
#define USBD_CDC_CLASS    &USBD_CDC
/**
  * @}
  */

/** @defgroup USB_CORE_Exported_Functions
  * @{
  */
uint8_t  USBD_CDC_RegisterInterface  (USBD_HandleTypeDef   *pdev,
                                      USBD_CDC_ItfTypeDef *fops);

uint8_t  USBD_CDC_SetTxBuffer        (USBD_HandleTypeDef   *pdev,
                                      uint8_t  *pbuff,
                                      uint16_t length);

uint8_t  USBD_CDC_SetRxBuffer        (USBD_HandleTypeDef   *pdev,
                                      uint8_t  *pbuff);

uint8_t  USBD_CDC_ReceivePacket      (USBD_HandleTypeDef *pdev);

uint8_t  USBD_CDC_TransmitPacket     (USBD_HandleTypeDef *pdev);
/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif  /* __USB_CDC_H */
/**
  * @}
  */

/**
  * @}
  */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
